//
//  ViewController.swift
//  BankOfChina
//
//  Created by mac on 2023/11/19.
//

import UIKit
import SnapKit
class ViewController: UIViewController {
    lazy var progressView:UIProgressView = {
       let progress = UIProgressView.init()
        progress.trackTintColor = UIColor.white
        progress.progressTintColor = UIColor(hex: "#E7514B")
        progress.progress = 0.01
        return progress
    }()
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var maskImageView: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        self.view.addSubview(self.progressView)
        self.progressView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(44)
            make.height.equalTo(2)
        }
        
        let after = getStamp() + Int(60 * 30)
        self.timeLabel.text = self.timeStampToStringDetail(String(after))
        
        GCDTimer.start(1, 60) {isFinish,count,intTimeCount in
            self.progressView.progress = Float(0.58 * intTimeCount)
            if (self.progressView.progress > 0.65){
                self.maskImageView.isHidden = true
                self.progressView.isHidden = true
            }
        }
    }
    override var preferredStatusBarStyle: UIStatusBarStyle {
      return .default
    }
    func timeStampToStringDetail(_ timeStamp:String)->String {
       let string = NSString(string: timeStamp)
       let timeSta:TimeInterval = string.doubleValue
       let dfmatter = DateFormatter()
       dfmatter.dateFormat="yyyy/MM/dd HH:mm"
       let date = Date(timeIntervalSince1970: timeSta)
       return dfmatter.string(from: date)
   }
    
    func getStamp()->Int{
       //获取当前时间戳
       let date = Date()
       let timeInterval:Int = Int(date.timeIntervalSince1970)
       return timeInterval
   }
    
    @IBAction func back(_ sender: Any) {
        self.dismiss(animated: false)
    }
    
    @IBAction func push122(_ sender: Any) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc11 = storyboard.instantiateViewController(withIdentifier: "ViewController2")
        vc11.modalPresentationStyle = .currentContext
        self.present(vc11, animated: false)
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.isNavigationBarHidden = true
    }

}

